﻿using Rebus.Activation;
using Rebus.Config;
using Rebus.Handlers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rebus.Demo.Start1
{
    class Program
    {
        static void Main(string[] args)
        {

            using (var activator = new BuiltinHandlerActivator())
            {
                
                Configure.With(activator)
                    .Transport(t => t.UseMsmq("inputqueue"))
                    .Start();
                activator.Register(() => new PrintDateTime());
                var timer = new System.Timers.Timer();
                timer.Elapsed += delegate { activator.Bus.SendLocal(DateTime.Now).Wait(); };
                timer.Interval = 1000;
                timer.Start();
                Console.WriteLine("Press enter to quit");
                Console.ReadLine();
            }
        }
    }
    public class PrintDateTime : IHandleMessages<DateTime>
    {
        public async Task Handle(DateTime currentDateTime)
        {

            Console.WriteLine("The time is {0}", currentDateTime);
        }
    }
}
